'use strict';

module.exports = app => {
<<<<<<< HEAD
  const { STRING, INTEGER, DATE, TEXT } = app.Sequelize;

  const Job = app.model.define('job', {
    id: {
      type: INTEGER,
      primaryKey: true,
      autoIncrement: true,
      comment: '岗位ID'
    },
    title: {
      type: STRING(100),
      allowNull: false,
      comment: '岗位名称'
    },
    company: {
      type: STRING(100),
      allowNull: false,
      comment: '公司名称'
    },
    salary: {
      type: STRING(50),
      allowNull: false,
      comment: '薪资范围'
    },
    location: {
      type: STRING(50),
      allowNull: false,
      comment: '工作地点'
    },
    description: {
      type: TEXT,
      allowNull: true,
      comment: '岗位描述'
    },
    tags: {
      type: STRING(255),
      allowNull: true,
      comment: '岗位标签'
    },
    logo: {
      type: STRING(255),
      allowNull: true,
      comment: '公司Logo'
    },
    posted_time: {
      type: DATE,
      allowNull: true,
      comment: '发布时间'
    },
    created_at: {
      type: DATE,
      allowNull: true,
      comment: '创建时间'
    },
    updated_at: {
      type: DATE,
      allowNull: true,
      comment: '更新时间'
    }
  }, {
    tableName: 'jobs',
    underscored: true
=======
  const { STRING, INTEGER, TEXT, DATE, BOOLEAN } = app.Sequelize;

  const Job = app.model.define('job', {
    jobId: {
      type: INTEGER,
      primaryKey: true,
      autoIncrement: true,
      field: 'job_id',
      comment: '岗位编号'
    },
    enterpriseId: {
      type: INTEGER,
      allowNull: false,
      field: 'enterprise_id',
      comment: '企业编号'
    },
    jobName: {
      type: STRING(100),
      allowNull: false,
      field: 'job_name',
      comment: '岗位名称'
    },
    jobDescription: {
      type: TEXT,
      allowNull: true,
      field: 'job_description',
      comment: '岗位描述'
    },
    jobRequirements: {
      type: TEXT,
      allowNull: true,
      field: 'job_requirements',
      comment: '岗位要求'
    },
    jobStatus: {
      type: STRING(20),
      allowNull: false,
      defaultValue: 'active',
      field: 'job_status',
      comment: '岗位状态：active-招聘中，inactive-已暂停，closed-已结束'
    },
    location: {
      type: STRING(50),
      allowNull: true,
      comment: '工作地点'
    },
    salary: {
      type: STRING(50),
      allowNull: true,
      comment: '薪资范围'
    },
    experience: {
      type: STRING(50),
      allowNull: true,
      comment: '工作经验要求'
    },
    education: {
      type: STRING(50),
      allowNull: true,
      comment: '学历要求'
    },
    category: {
      type: STRING(50),
      allowNull: true,
      comment: '岗位分类'
    },
    hiringCount: {
      type: INTEGER,
      allowNull: true,
      defaultValue: 1,
      field: 'hiring_count',
      comment: '招聘人数'
    },
    isTop: {
      type: BOOLEAN,
      allowNull: false,
      defaultValue: false,
      field: 'is_top',
      comment: '是否置顶'
    },
    viewCount: {
      type: INTEGER,
      allowNull: true,
      defaultValue: 0,
      field: 'view_count',
      comment: '浏览次数'
    },
    applicationCount: {
      type: INTEGER,
      allowNull: true,
      defaultValue: 0,
      field: 'application_count',
      comment: '投递次数'
    },
    createTime: {
      type: DATE,
      allowNull: false,
      field: 'create_time',
      defaultValue: app.Sequelize.NOW,
      comment: '创建时间'
    },
    updateTime: {
      type: DATE,
      allowNull: false,
      field: 'update_time',
      defaultValue: app.Sequelize.NOW,
      comment: '更新时间'
    }
  }, {
    tableName: 'job',
    timestamps: false,
    comment: '岗位表'
>>>>>>> resume
  });

  // 定义关联关系
  Job.associate = function() {
<<<<<<< HEAD
    // 一个岗位可以被多个用户收藏
    app.model.Job.hasMany(app.model.Favorite, {
      foreignKey: 'job_id',
      as: 'jobFavorites'  // 修改别名，避免冲突
=======
    // 岗位属于企业
    app.model.Job.belongsTo(app.model.Enterprise, {
      foreignKey: 'enterpriseId',
      targetKey: 'enterpriseId',
      as: 'enterprise'
    });
    // 一个岗位有多个投递记录
    app.model.Job.hasMany(app.model.JobApplication, {
      foreignKey: 'jobId',
      sourceKey: 'jobId',
      as: 'applications'
>>>>>>> resume
    });
  };

  return Job;
<<<<<<< HEAD
};
=======
};











































>>>>>>> resume
